<?php
use yii\helpers\Url;

$web = Url::base();
$this->title = '创建新机构';
?>

<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/apply-for-institution.css"/>

<div class="main">
    <div style="border-bottom: 1px solid #dfdfdf;">
        <img src="<?= $web ?>/images/mall-m/apply-for-institution-1.png" style="width: 16rem;display: none;">
    </div>
    <form method="post" action="apply-for-institution-form">
        <div class="frame">
            <span class="verification-code">企业全称：</span>
            <input type="text" name="txtName" id="txtName">
        </div>
        <div class="frame">
            <span class="verification-code">联系人&nbsp;&nbsp;&nbsp;&nbsp;：</span>
            <input type="text" name="txtContacter" id="txtContacter" maxlength="30">
        </div>

        <div class="frame">
            <script>
                function tel(v) {
                    var myreg = /^(\d{11})$/;
                    if (myreg.test(v) == false) {
                        alert('请输入有效的手机号码！');
                        return false;
                    }
                    return true;
                }
            </script>
            <span class="verification-code">联系手机：</span>
            <input type="tel" maxlength="11" name="txtContacterPhone" id="txtPhone">
        </div>
        <div class="frame" style="border: none">
            <span class="verification-code">验证码&nbsp;&nbsp;&nbsp;&nbsp;：</span>
            <input type="text" style="width: 5rem" name="txtVerificationCode" id="txtVerificationCode">

            <div class="get-verification-code" id="btnSmsVerificationCode">
                获取验证码<span class="get-verification-time"></span>
            </div>
            <script>
                $('#btnSmsVerificationCode').click(function () {
                    if ($(this).hasClass('get-verification-code-disabled')) {
                        return;
                    }

                    $(this).addClass('get-verification-code-disabled');
                    $(this).text('正在获取...');
                    var phone = $('#txtPhone').val().trim();
                    if (phone.length == 0) {
                        alert('请输入手机号码');
                        $(this).text('获取验证码');
                        $(this).removeClass('get-verification-code-disabled');
                        $('#txtPhone').focus();
                        return;
                    }
                    var that = this;
                    requestJson('send-sms-verification-code-handler', {phone: phone}, true, function (responseData) {
                        if (responseData.status != 0) {
                            $(that).text('获取验证码');
                            $(that).removeClass('get-verification-code-disabled');
                            alert(responseData.message);
                        } else {
                            verifyTimeoutValue = 60;
                            verifyTimeout();
                        }
                    }, function () {
                        $(that).text('获取验证码');
                        $(that).removeClass('get-verification-code-disabled');
                    });
                });

                var verifyTimeoutValue = 0;
                function verifyTimeout() {
                    if (verifyTimeoutValue > 0) {
                        $('#btnSmsVerificationCode').text('重新获取(' + verifyTimeoutValue + ')');
                        verifyTimeoutValue--;
                        setTimeout(verifyTimeout, 1000);
                    } else {
                        $('#btnSmsVerificationCode').text('获取验证码');
                        $('#btnSmsVerificationCode').removeClass('get-verification-code-disabled');
                    }
                }
            </script>
        </div>
        <div class="hr"></div>

        <div class="frame-address" style="height: 3rem;">
            <span class="verification-code">联系地址：</span>
            <textarea name="txtAddress" id="txtAddress" maxlength="100"></textarea>
        </div>
        <input type="submit" class="apply-button" value="申请使用">
    </form>
    <div>
        <img src="<?= $web ?>/images/mall-m/apply-for-institution-2.jpg" style="display: block;width: 16rem">
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("form").submit(function(e){
            var txtName = $("#txtName").val();
            if(txtName == ""){
                alert("企业全称不能为空");
                $("#txtName").focus();
                return false;
            }

            var txtContacter = $("#txtContacter").val();
            if(txtContacter == ""){
                alert("联系人不能为空");
                $("#txtContacter").focus();
                return false;
            }

            var txtPhone = $("#txtPhone").val();
            if(txtPhone == ""){
                alert("联系手机不能为空");
                $("#txtPhone").focus();
                return false;
            }

            var txtVerificationCode = $("#txtVerificationCode").val();
            if(txtVerificationCode == ""){
                alert("验证码不能为空");
                $("#txtVerificationCode").focus();
                return false;
            }


            var txtAddress = $("#txtAddress").val();
            if(txtAddress == ""){
                alert("联系地址不能为空");
                $("#txtAddress").focus();
                return false;
            }
        });
    });
</script>